package jjn.acwing.algorithm_basic.chapter1.pre_sum;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author Jiang Jining
 * @since 2023-09-22 19:44
 */
public class Acwing796 {
    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        String input = bufferedReader.readLine();
        String[] params = input.split(" ");
        int n = Integer.parseInt(params[0]);
        int m = Integer.parseInt(params[1]);
        int q = Integer.parseInt(params[2]);
        int[][] nums = new int[n + 1][m + 1];
        for (int i = 1; i <= n; i++) {
            String read = bufferedReader.readLine();
            String[] parts = read.split(" ");
            for (int j = 1; j <= m; j++) {
                nums[i][j] = Integer.parseInt(parts[j - 1]);
            }
        }
        int[][] prefix = new int[n + 1][m + 1];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                prefix[i][j] = prefix[i - 1][j] + prefix[i][j - 1]
                        - prefix[i - 1][j - 1] + nums[i][j];
            }
        }
        while (q-- > 0) {
            String in = bufferedReader.readLine();
            String[] parts = in.split(" ");
            int x1 = Integer.parseInt(parts[0]);
            int y1 = Integer.parseInt(parts[1]);
            int x2 = Integer.parseInt(parts[2]);
            int y2 = Integer.parseInt(parts[3]);
            int res = prefix[x2][y2] - prefix[x1 - 1][y2] - prefix[x2][y1 - 1] + prefix[x1 - 1][y1 - 1];
            System.out.println(res);
        }
    }
}
